home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_360 / uucp / uucp0.lzh / src / anews / raw.c < prev    next >
C/C++ Source or Header  |  1990-05-17  |  3KB  |  142 lines

  1.  
  2. #if defined(LATTICE) || defined(_DCC)
  3.  
  4. /*
  5.  * Routines specific to Lattice C.
  6.  */
  7.  
  8. /*
  9.  * raw.c
  10.  *
  11.  * This is a routine for setting a given stream to raw or cooked mode on the
  12.  * Amiga. This is useful when you are using Lattice C to produce programs
  13.  * that want to read single characters with the "getch()" or "fgetc" call.
  14.  *
  15.  * Written : 18-Jun-87 By Chuck McManis.
  16.  */
  17.  
  18. #include <exec/types.h>
  19. #include <libraries/dos.h>
  20. #include <libraries/dosextens.h>
  21.  
  22. #ifdef LATTICE
  23. #include <ios1.h>
  24. #endif
  25. #include <errno.h>
  26. #include <stdio.h>
  27.  
  28. /*
  29.  * Function raw() - Convert the specified file pointer to 'raw' mode. This
  30.  * only works on TTYs and essentially keeps DOS from translating keys for
  31.  * you, also (BIG WIN) it means getch() will return immediately rather than
  32.  * wait for a return. You lose editing features though.
  33.  */
  34.  
  35. long
  36. raw(fp)
  37. FILE *fp;
  38. {
  39.     struct MsgPort *mp;     /* The File Handle message port */
  40.     struct FileHandle *afh;
  41.     long        Arg[1], res;
  42.  
  43. #ifdef LATTICE
  44.     {
  45.     struct UFB     *ufb;
  46.     ufb = (struct UFB *) chkufb(fileno(fp));    /* Step one, get the file   */
  47.     afh = (struct FileHandle *) (ufb->ufbfh);
  48.     }
  49. #else
  50.     afh = (struct FileHandle *)fdtofh(fileno(fp));
  51. #endif
  52.  
  53.     if (!IsInteractive(afh)) {  /* Step two, check to see if it's a console */
  54.     errno = ENOTTY;
  55.     return (-1);
  56.     }
  57.     /* Step three, get it's message port. */
  58.     mp = ((struct FileHandle *) (BADDR(afh)))->fh_Type;
  59.     Arg[0] = -1L;
  60.     res = SendPacket(mp, ACTION_SCREEN_MODE, Arg, 1);   /* Put it in RAW: mode */
  61.     if (res == 0) {
  62.     errno = ENXIO;
  63.     return (-1);
  64.     }
  65.     return (0);
  66. }
  67.  
  68. /*
  69.  * Function - cooked() this function returns the designate file pointer to
  70.  * its normal, wait for a <CR> mode. This is exactly like raw() except that
  71.  * it sends a 0 to the console to make it back into a CON: from a RAW:
  72.  */
  73.  
  74. long
  75. cooked(fp)
  76. FILE *fp;
  77. {
  78.     struct MsgPort *mp;     /* The File Handle message port */
  79.     struct FileHandle *afh;
  80.     long        Arg[1], res;
  81.  
  82. #ifdef LATTICE
  83.     {
  84.     struct UFB     *ufb;
  85.     ufb = (struct UFB *) chkufb(fileno(fp));
  86.     afh = (struct FileHandle *) (ufb->ufbfh);
  87.     }
  88. #else
  89.     afh = (struct FileHandle *)fdtofh(fileno(fp));
  90. #endif
  91.  
  92.     if (!IsInteractive(afh)) {
  93.     errno = ENOTTY;
  94.     return (-1);
  95.     }
  96.     mp = ((struct FileHandle *) (BADDR(afh)))->fh_Type;
  97.     Arg[0] = 0;
  98.     res = SendPacket(mp, ACTION_SCREEN_MODE, Arg, 1);
  99.     if (res == 0) {
  100.     errno = ENXIO;
  101.     return (-1);
  102.     }
  103.     return (0);
  104. }
  105.  
  106. #else            /*    ----------------------------------------------    */
  107.  
  108. /*
  109.  * Routines specific to Aztec C.
  110.  */
  111.  
  112. #include "news.h"
  113. #include <sgtty.h>
  114. #include <fcntl.h>
  115.  
  116. /*
  117.  * put the console into raw or cooked mode
  118.  */
  119.  
  120. raw(FILE *f)
  121. {
  122.     struct sgttyb ttyinfo;
  123.  
  124.     if (ioctl(fileno(f), TIOCGETP, &ttyinfo) < 0) return -1;
  125.     ttyinfo.sg_flags |= RAW;
  126.     if (ioctl(fileno(f), TIOCSETP, &ttyinfo) < 0) return -1;
  127.     return 0;
  128. }
  129.  
  130. cooked(FILE *f)
  131. {
  132.     struct sgttyb ttyinfo;
  133.  
  134.     if (ioctl(fileno(f), TIOCGETP, &ttyinfo) < 0) return -1;
  135.     ttyinfo.sg_flags &= ~RAW;
  136.     if (ioctl(fileno(f), TIOCSETP, &ttyinfo) < 0) return -1;
  137.     return 0;
  138. }
  139.  
  140. #endif
  141.  
  142.